1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package net.sf.pmr.agilePlanning.service;
36
37 import java.util.Iterator;
38 import java.util.Set;
39
40 import net.sf.pmr.agilePlanning.AgilePlanningObjectFactory;
41 import net.sf.pmr.agilePlanning.domain.iteration.Iteration;
42 import net.sf.pmr.agilePlanning.domain.story.Story;
43 import net.sf.pmr.agilePlanning.domain.story.StoryRepository;
44 import net.sf.pmr.agilePlanning.domain.story.task.Task;
45 import net.sf.pmr.agilePlanning.domain.story.task.TaskValidator;
46 import net.sf.pmr.core.CoreObjectFactory;
47 import net.sf.pmr.core.domain.user.User;
48 import net.sf.pmr.keopsframework.domain.validation.Errors;
49
50 /***
51 * @author Arnaud Prost (arnaud.prost@gmail.com)
52 */
53 public class StoryServiceImpl implements StoryService {
54
55 /***
56 * Validator
57 */
58 private TaskValidator taskValidator;
59
60 /***
61 * Repository
62 */
63 private StoryRepository storyRepository;
64
65 public StoryServiceImpl(final TaskValidator taskValidator,
66 final StoryRepository storyRepository) {
67 super();
68 this.taskValidator = taskValidator;
69 this.storyRepository = storyRepository;
70 }
71
72 /***
73 * @see net.sf.pmr.agilePlanning.service.StoryService#add(int, java.lang.String, java.lang.String, int)
74 */
75 public Errors add(final int projectPersistanceId,
76 final String shortDescription, final String description,
77 final int estimate, final int iterationPersistanceId) {
78
79
80 Story story = AgilePlanningObjectFactory.getStory();
81 story.getBasicProject().setPersistanceId(projectPersistanceId);
82 story.setDescription(description);
83
84 Iteration iteration = AgilePlanningObjectFactory.getIteration();
85 iteration.setPersistanceId(iterationPersistanceId);
86
87 story.setIteration(iteration);
88
89 story.setEstimate(estimate);
90 story.setShortDescription(shortDescription);
91
92
93 storyRepository.addOrUpdate(story);
94
95
96 return AgilePlanningObjectFactory.getErrors();
97
98 }
99
100 /***
101 * @see net.sf.pmr.agilePlanning.service.StoryService#addTask(int, int,
102 * java.lang.String, int)
103 */
104 public Errors addTask(final int storyPersistanceId,
105 final int numberOfIdealDays, final String shortDescription,
106 final int developperPersistanceId) {
107
108
109 Task task = AgilePlanningObjectFactory.getTask();
110 User user = CoreObjectFactory.getUser();
111 user.setPersistanceId(developperPersistanceId);
112
113 task.setDevelopper(user);
114 task.setIdealDay(numberOfIdealDays);
115 task.setShortDescription(shortDescription);
116
117
118 Errors errors = taskValidator.validate(task);
119
120 if (!errors.hasErrors()) {
121
122
123 Story story = storyRepository
124 .findByPersistanceId(storyPersistanceId);
125
126
127 if (story != null) {
128
129 story.getTasks().add(task);
130
131 storyRepository.addOrUpdate(story);
132
133 }
134
135 }
136
137 return errors;
138
139 }
140
141 /***
142 // * @see net.sf.pmr.agilePlanning.service.StoryService#delete(int, long)
143 // */
144
145
146
147
148 /***
149 * @see net.sf.pmr.agilePlanning.service.StoryService#findByPersistanceId(int)
150 */
151 public Story findByPersistanceId(final int persistanceId) {
152 return storyRepository.findByPersistanceId(persistanceId);
153 }
154
155 /***
156 * @see net.sf.pmr.agilePlanning.service.StoryService#findByProjectPersistanceId(int)
157 */
158 public Set findByProjectPersistanceId(final int projectPersistanceId) {
159 return storyRepository.findByProjectPersistanceId(projectPersistanceId);
160 }
161
162 /***
163 * @see net.sf.pmr.agilePlanning.service.StoryService#findTaskByPersistanceId(int)
164 */
165 public Task findTaskByPersistanceId(final int persistanceId) {
166 return storyRepository.findTaskByPersistanceId(persistanceId);
167 }
168
169 /***
170 * @see net.sf.pmr.agilePlanning.service.StoryService#update(int, java.lang.String, java.lang.String, int, int, int, long)
171 */
172 public Errors update(final int projectPersistanceId,
173 final String shortDescription, final String description,
174 final int estimate, final int iterationPersistanceId, final int persistanceId,
175 final long persistanceVersion) {
176
177
178 Story story = AgilePlanningObjectFactory.getStory();
179 story.getBasicProject().setPersistanceId(projectPersistanceId);
180 story.setDescription(description);
181 story.setEstimate(estimate);
182
183 Iteration iteration = AgilePlanningObjectFactory.getIteration();
184 iteration.setPersistanceId(iterationPersistanceId);
185
186 story.setIteration(iteration);
187 story.setPersistanceId(persistanceId);
188 story.setPersistanceVersion(persistanceVersion);
189 story.setShortDescription(shortDescription);
190
191
192 storyRepository.addOrUpdate(story);
193
194
195 return AgilePlanningObjectFactory.getErrors();
196
197 }
198
199 /***
200 * @see net.sf.pmr.agilePlanning.service.StoryService#updateTask(int, int, java.lang.String, int, int, long)
201 */
202 public Errors updateTask(final int storyPersistanceId,
203 final int numberOfIdealDays, final String shortDescription,
204 final int developperPersistanceId, final int persistanceId,
205 final long persistanceVersion) {
206
207
208 Task task = AgilePlanningObjectFactory.getTask();
209 User user = CoreObjectFactory.getUser();
210 user.setPersistanceId(developperPersistanceId);
211
212 task.setDevelopper(user);
213 task.setPersistanceId(persistanceId);
214 task.setPersistanceVersion(persistanceVersion);
215 task.setIdealDay(numberOfIdealDays);
216 task.setShortDescription(shortDescription);
217
218
219 Errors errors = taskValidator.validate(task);
220
221 if (!errors.hasErrors()) {
222
223
224 Story story = storyRepository
225 .findByPersistanceId(storyPersistanceId);
226
227 if (story != null) {
228
229
230 for (Iterator iterator = story.getTasks().iterator(); iterator
231 .hasNext();) {
232 Task taskToUpdate = (Task) iterator.next();
233
234 if (task.getPersistanceId() == taskToUpdate
235 .getPersistanceId()) {
236
237 taskToUpdate.setDevelopper(task.getDevelopper());
238 taskToUpdate.setIdealDay(task.getIdealDay());
239 taskToUpdate.setPersistanceVersion(task
240 .getPersistanceVersion());
241 taskToUpdate.setShortDescription(task
242 .getShortDescription());
243
244
245 storyRepository.addOrUpdate(story);
246
247
248 break;
249
250 }
251
252 }
253
254 }
255
256 }
257
258 return errors;
259
260 }
261 }